package cn.wolfcode.luowowo.mgrsite.web.controller;

import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.query.TravelCommendQuery;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.util.AJaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("travelCommend")
public class TravelCommendController {

    @Reference
    private ITravelCommendService commendService;

    @Reference
    private ITravelService travelService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelCommendQuery qo, Model model){
        PageInfo<TravelCommend> pageInfo = commendService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "travelCommend/list";
    }

    @RequestMapping("getTravels")
    @ResponseBody
    public List<Travel> getTravels(){
        return travelService.list();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public AJaxResult saveOrUpdate(TravelCommend travelCommend){
        commendService.saveOrUpdate(travelCommend);
        return AJaxResult.SUCCESS();
    }

    @RequestMapping("delete")
    @ResponseBody
    public AJaxResult delete(Long id){
        commendService.delete(id);
        return AJaxResult.SUCCESS();
    }
}
